<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <title>规则引擎详情</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <%@include file="/WEB-INF/pages/common/taglib.jsp" %>
    <%@include file="/WEB-INF/pages/common/common.jsp" %>
    <script type="text/javascript" src="${basePath}/js/ecommerce.js"></script>
    <script type="text/javascript" src="${basePath}/plugins/syntaxhighlighter/scripts/shCore.js"></script>
    <script class="javascript" src="${basePath}/plugins/syntaxhighlighter/scripts/shBrushJava.js"></script>
    <link type="text/css" rel="stylesheet" href="${basePath}/plugins/syntaxhighlighter/styles/shCoreDefault.css"/>
    <style>

        .table3 tr {
            height: 40px;
            line-height: 40px;
            border: 1px #ccc solid
        }
    </style>
</head>
<body>
<div class="content content_frame">

    <h3 class="mainTitle"><img src="${basePath}/images/icon2.png"/>规则引擎详情</h3>
    <br/>
    <ul class="contentNav dib-wrap">
        <c:if test="${false==modify}">
            <li class="dib" id="btnSave">
                <a onclick="javascript:save()">
                    <i class='fa fa-save'></i>&nbsp;&nbsp;保&nbsp;存 </a>
            </li>
        </c:if>
        <li class="dib">
            <a onclick="javascript:history.go(-1)">
                <i class='fa fa-reply'></i>&nbsp;&nbsp;返&nbsp;回 </a>
        </li>
    </ul>
    <br/>

    <form id="detailForm">
        <input type="hidden" name="ruleId" value="${tDroolRule.ruleId}">
        <table class="table3">
            <tr>
                <th colspan="4">规则信息</th>
            </tr>
            <tr>
                <td width="120">规则名称</td>
                <td>
                    <input name="ruleName" value="${tDroolRule.ruleName}"/>
                </td>

                <td width="120">规则状态</td>
                <td>
                    <ui:tsingletableautocomplete
                            keyFieldName="ruleStatus"
                            valueFieldName="ruleStatusName"
                            tableName="DICT_ITEM"
                            key="ITEM_KEY"
                            customData='[{"id":"在用------===1","ITEM_KEY":"在用","ITEM_VALUE":"1"},{"id":"禁用------===0","ITEM_KEY":"禁用","ITEM_VALUE":"0"}]'
                            value="ITEM_VALUE"
                            defaultValue="${tDroolRule.ruleStatus=='1'?'在用':(tDroolRule.ruleStatus=='0'?'禁用':'')}"
                            defaultKey="${tDroolRule.ruleStatus}"
                            />
                </td>
            </tr>
            <tr>
                <td width="120">规则修改时间</td>
                <td>
                    <input name="ruleDate" id="ruleDate" value="${tDroolRule.ruleDate}"/>
                </td>
                <td width="120">规则修改人</td>
                <td>
                    <input name="ruleOperator" id="ruleOperator" value="${tDroolRule.ruleOperator}"/>
                </td>
            </tr>
            <tr>
                <td width="120">规则描述</td>
                <td>

                    <textarea style="padding: 0px" name="ruleDesc">${tDroolRule.ruleDesc}</textarea>

                </td>
            </tr>
        </table>
        <table class="table3">
            <tr>
                <th colspan="1">规则编辑
                </th>
            </tr>
            <tr>
                <td width="360">
                    <div style="min-height: 400px;min-width:720px"
                         <c:if test="${false==modify}">contenteditable="true"</c:if>>
                        <pre class="brush: java;">${tDroolRule.ruleContent}</pre>
                    </div>
                </td>
            </tr>
        </table>
    </form>
</div>
</body>
<script type="text/javascript">
    function getCodeValue() {
        var str = "";
        var lines = $("div[class^='line number']");
        for (var i = 0; i < lines.length; i++) {
            var add = false;
            var line = $(lines[i]).find("code");
            for (var j = 0; j < line.length; j++) {
                str += line[j].innerHTML;
                add = true;
            }
            if (add) {
                str += "</br>";
            }
        }
        if ("" == str) {
            for (var i = 0; i < lines.length; i++) {
                str += lines[i].innerHTML;
                str += "</br>";
            }
        }
        return str;
    }
    function save() {
        SyntaxHighlighter.highlight();
        var jsonData = form2Json("detailForm");
        jsonData['ruleContent'] = getCodeValue();
        $.ajax({
            type: "post",
            async: false,
            url: $basePath + "/rules/saveTDroolRule",
            data: jsonData,
            success: function (result) {
                if (result) {
                    if ("success" == result) {
                        showOKMessage('保存成功!', '', function () {
                        });
                    } else {
                        ShowMessages(result, "系统提示", "msgwaring", null, 0);
                    }
                } else {
                    ShowMessages("保存失败", "系统提示", "msgwaring", null, 0);
                }
            }
        });
    }
    $(function () {
        $("#detailForm input,textarea,#btnSave,select").attr("disabled", ${modify});
        $("#ruleDate,#ruleOperator").attr("disabled", true);
        document.onkeydown = function (e) {
        }
        SyntaxHighlighter.highlight();
    });

</script>
</html>
